<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    function ajax1() {
      return new Promise((resolve, reject) => {
        // 定时器就是模拟请求时间
        setTimeout(() => {
          resolve('ajax1请求结果')
        }, 3000);
      })
    }

    function ajax2() {
      return new Promise((resolve, reject) => {
        // 定时器就是模拟请求时间
        setTimeout(() => {
          resolve('ajax2请求结果')
        }, 5000);
      })
    }


    async function fn() {

      // const res1 = await ajax1();
      // console.log(res1);

      // const res2 = await ajax2();
      // console.log(res2);

      console.log('开始时间');

      // 同时发送多个请求，什么时候才往后执行代码，等两个请求都完成时才往后
      const res = await Promise.all([ajax1(), ajax2()]);

      console.log(res[0]);
      console.log(res[1]);
      console.log('结束时间');

    }

    fn()


  </script>
</body>

</html>